<?php
/*
	[Bidcms.com!] (C)2009-2011 Bidcms.com.
	This is NOT a freeware, use is subject to license terms
	$author limengqi
	$Id: showcase.class.php 2010-08-24 10:42 $
*/
if(!defined('IN_BIDCMS')) {
	exit('Access Denied');
}
header("content-type:text/html;charset=utf-8");
class payment_controller extends controller
{
	function __construct(){
		
		
	}
	function index_action(){
		global $store_id,$post;
		$mod=$this->bidcms_model('payment_base');
		if($this->bidcms_submit_check('commit')){
            $updateid = intval($post['updateid']);
            $data['name'] = $post['name'];
            $data['platform_id'] = $post['platform'];
            $data['gateway'] = $post['url'];
            $data['merchant_id'] = $post['mid'];
            $data['merchant_key'] = $post['mkey'];
            $data['pay_type'] = $post['paycode'];
            $data['data'] = $post['ext'];
            $data['updatetime'] = time();
            if($updateid>0){
              $mod->update_data(array('and id=:id',array(':id'=>$updateid)),$data);
            } else {
              $mod->insert_data($data);
            }
            $this->bidcms_success(array(),'提交成功');
		} else {
            $platforms = $this->bidcms_model('payment_platform')->get_page(array(),array('index'=>'id'));
            
			$shopage = array('isshow'=>1,'current_page'=>$get['page'],'page_size'=>20,'url'=>'');
			$list=$mod->get_page(array(),$showpage);
            $pageinfo = $this->bidcms_parse_page($list->page,$showpage);
			include $this->bidcms_template('index');
		}
	}
	function platform_action(){
		global $store_id,$post;
		$mod=$this->bidcms_model('payment_platform');
		if($this->bidcms_submit_check('commit')){
            $updateid = intval($post['updateid']);
			$data['name'] = $post['name'];
            $data['code'] = $post['code'];
            if($updateid>0){
              $mod->update_data(array('and id=:id',array(':id'=>$updateid)),$data);
            } else {
              $mod->insert_data($data);
            }
            $this->bidcms_success(array(),'提交成功');
		} else {
			$list = $mod->get_page();
			include $this->bidcms_template('platform');
		}
	}
	function state_action(){
		global $store_id,$post;
		$mod=$this->bidcms_model('payment_base');
		if($this->bidcms_submit_check('commit')){
            $updateid = intval($post['id']);
            $p = $mod->get_one(array('and id=:id',array(':id'=>$updateid)));
            if($p){
              if($p['state'] == 0){
                $mod->update_data(array('and id=:id',array(':id'=>$updateid)),array('state'=>1));
                $this->bidcms_success(array('state'=>'1'),'开启');
              } else {
                $mod->update_data(array('and id=:id',array(':id'=>$updateid)),array('state'=>0));
                $this->bidcms_success(array('state'=>'0'),'关闭');
              }
            }
		}
	}
	
	function pay_action(){
		global $store_id;
		$mod=$this->bidcms_model('shop_pay');
		$type=in_array($_GET['type'],array('alipay','jd','paypal','paybao','union','bill'))?$_GET['type']:'alipay';
		if($this->bidcms_submit_check('commit')){
			$_POST['shop_id']=$store_id;
			$status=$mod->save($_POST);
			if($status>0){
				echo '{"status":1}';
			} else {
				echo '{"status":0,"msg":"未改变任何数据"}';
			}
			exit;
		}
		$shopinfo=$mod->get_list($store_id);
		
		include $this->bidcms_template($type.'_pay');
	}
}
